package com.zbkj.dal.base.enums;

import com.zbkj.dal.common.exception.CrmebException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@AllArgsConstructor
public enum ExpressOrderType {

    /**
     * 物流订单类型
     */

    // ----------------- 买入订单 -----------------

    // 购买订单 物流订单
    PURCHASE("购买订单 物流订单", OrderType.PURCHASE),

    // ----------------- 承享订单 -----------------

    // 承享订单创建 物流订单
    RENT_CREATE("承享订单创建 物流订单", OrderType.RENT),

    // 承享订单归还 物流订单
    RENT_RETURN("承享订单归还 物流订单", OrderType.RENT),

    // ----------------- 供享订单 -----------------

    // 供享订单 初评收货
    SHARED_INITIAL_EVALUATION_RCV("供享订单 初评收货", OrderType.SHARED),
    // 供享订单 取消供享
    SHARED_CANCEL("供享订单 取消供享", OrderType.SHARED),

    ;

    private final String message;
    private final OrderType orderType;

    public static ExpressOrderType of(String code) {
        for (ExpressOrderType value : ExpressOrderType.values()) {
            if (StringUtils.equals(value.name(), code)) {
                return value;
            }
        }
        throw new CrmebException("不支持的类型");
    }

    public static ExpressOrderType byOrderType(Integer orderType) {
        for (ExpressOrderType value : ExpressOrderType.values()) {
            if (value.orderType != null && Objects.equals(value.orderType.getCode(), orderType)) {
                return value;
            }
        }
        throw new CrmebException("不支持的类型");
    }
}
